/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.qhq.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.qhq.entity.SchoolParent;
import com.thinkgem.jeesite.modules.qhq.dao.SchoolParentDao;
import com.thinkgem.jeesite.modules.qhq.entity.PrentSystemlist;
import com.thinkgem.jeesite.modules.qhq.dao.PrentSystemlistDao;

/**
 * 学院表Service
 * @author 秦华权
 * @version 2017-11-28
 */
@Service
@Transactional(readOnly = true)
public class SchoolParentService extends CrudService<SchoolParentDao, SchoolParent> {

	@Autowired
	private PrentSystemlistDao prentSystemlistDao;
	
	public SchoolParent get(String id) {
		SchoolParent schoolParent = super.get(id);
		schoolParent.setPrentSystemlistList(prentSystemlistDao.findList(new PrentSystemlist(schoolParent)));
		return schoolParent;
	}
	
	public List<SchoolParent> findList(SchoolParent schoolParent) {
		return super.findList(schoolParent);
	}
	
	public Page<SchoolParent> findPage(Page<SchoolParent> page, SchoolParent schoolParent) {
		return super.findPage(page, schoolParent);
	}
	
	@Transactional(readOnly = false)
	public void save(SchoolParent schoolParent) {
		super.save(schoolParent);
		for (PrentSystemlist prentSystemlist : schoolParent.getPrentSystemlistList()){
			if (prentSystemlist.getId() == null){
				continue;
			}
			if (PrentSystemlist.DEL_FLAG_NORMAL.equals(prentSystemlist.getDelFlag())){
				if (StringUtils.isBlank(prentSystemlist.getId())){
					prentSystemlist.setPrentId(schoolParent);
					prentSystemlist.preInsert();
					prentSystemlistDao.insert(prentSystemlist);
				}else{
					prentSystemlist.preUpdate();
					prentSystemlistDao.update(prentSystemlist);
				}
			}else{
				prentSystemlistDao.delete(prentSystemlist);
			}
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(SchoolParent schoolParent) {
		super.delete(schoolParent);
		prentSystemlistDao.delete(new PrentSystemlist(schoolParent));
	}
	
}